<template>
  <div class="index">
    <el-container>
      <el-header height="68px">
        <m-header></m-header>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <m-aside></m-aside>
        </el-aside>
        <el-main>
          <div class="main">
            <div class="header-top">
              <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>系统通知管理</el-breadcrumb-item>
              </el-breadcrumb>
              <h2 class="title">系统通知管理</h2>
            </div>
            <div class="row">
              <el-row style="margin-bottom:30px">
                <el-button type="primary"  @click="dialogVisible = true">添加新通知</el-button>
              </el-row>
              <el-table
                :data="tableData"
                border
                :cell-style="{'text-align':'center'}"

                :header-cell-style="{
                  'background-color': '#f5f5f5',
                  'color':'#555',
                  'text-align':'center'
                }"
                style="width: 100%">
                
                <el-table-column
                  prop="noticeTitle"
                  label="通知标题">
                </el-table-column>
                <el-table-column
                  prop="noticeContent"
                  label="通知内容">
                </el-table-column>  
  
                <el-table-column
                  label="操作"
                  width="300">
                  <template slot-scope="scope">
                    <el-button @click="deleteClick(scope.row)" type="text" size="small">删除</el-button>
                  </template>
                </el-table-column>
                
              </el-table>
              <div class="block">
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage"
                  :page-sizes="[20, 50, 100]"
                  :page-size="pagesize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
                </el-pagination>
              </div>
    
            </div>

          </div>
        </el-main>
      </el-container>
      <el-dialog
        :visible.sync="dialogVisible"

        :close-on-click-modal='boole'
        custom-class="diaself"
        center
        top='30vh'
        width="28%">
        <el-form ref="form" :model="form" label-position="top" class="text-style">
          <el-form-item label="通知标题">
            <el-input v-model="form.noticeTitle"></el-input>
          </el-form-item>
          <el-form-item label="通知内容">

            <el-input type="textarea" v-model="form.noticeContent"></el-input>

          </el-form-item>
          
        </el-form>
        <span slot="footer" class="dialog-footer" style="text-align:center">
          <el-button type="primary" @click="submit" >提 交</el-button>
        </span>
      </el-dialog>
    </el-container>
  </div>
</template>
<script>
import { getCookie,timeChange,getQueryString } from "./until/index";
function init(){
  this.$ajax.get("admGetSysNoticeList.ashx?token="+getCookie("token")+'&pz='+this.pagesize+
        '&pi='+this.currentPage)
      .then(res => {
        
        if (res.data.code === "200") {
          var data = res.data.data;
          this.total = Number(data.rowCount) 
          
          this.tableData = data.NoticeList;

        } else {
          this.$message.error(res.data.msg );
        }
      })
      .catch(error => {
        console.log(error);
      });
}
function removeException(row){//移除
  this.$ajax.get("admDeleteSysNotice.ashx?&token=" +getCookie("token")+'&noticeID='+row)
      .then(res => {
        if (res.data.code === "200") {
          this.$message({
            type: 'success',
            message: res.data.msg,
            onClose:()=>{

              init.call(this)
            }
          });

        } else {
          this.$message.error(res.data.msg );
        }
      })
      .catch(error => {
        console.log(error);
      });
}
function pushTo (row,count){ //新增
  this.$ajax.get("admSaveSysNotice.ashx?token=" +getCookie("token")+'&noticeTitle='+row+'&noticeContent='+count)
      .then(res => {
        if (res.data.code === "200") {
          
          this.$message({
            type: 'success',
            message: res.data.msg,
            onClose:()=>{
              init.call(this)
              this.dialogVisible = false
            }
          });
        } else {
          this.$message.error(res.data.msg );
        }
      })
      .catch(error => {
        console.log(error);
      });
}

export default {
  data() {
    return {
      pagesize: 20, //每页显示条数
      currentPage: 1, //初始页
      total: 0, //总条数
      dialogVisible: false,
      boole:false,
      tableData: [],
      type:'',
      form:{
        noticeTitle:'',
        noticeContent:''
      }

    };
  },
  created() {
    
    
    init.call(this)
  },
  methods: {
    
    deleteClick(row){//从列表中删除
      
      this.$confirm('确定删除 ?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          
          removeException.call(this,row.noticeID)
           
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作'
          });          
        });

      
    },
    submit(){

      pushTo.call(this,this.form.noticeTitle,this.form.noticeContent)
    },
     handleCurrentChange(num) {
      this.currentPage = num;
      init.call(this)
    },
    handleSizeChange(val) {
      this.pagesize = val;
      init.call(this)
    },
    
  }
};
</script>
<style scoped>
.index {
  overflow: hidden;
}
.water{margin-right: 20px;display: inline-block}
.waterTime{font-size: 14px;color: #606266;padding: 0 12px 0 0;box-sizing: border-box;}
.el-header {
  background-color: #3a4759;
  color: #fff;
}
.el-aside {
  background-color: #485668;
  color: #333;
  text-align: center;
  line-height: 200px;
  overflow: hidden;
}
.el-main {
  background-color: #f0f2f5;
  color: #333;
  text-align: center;
  height: 100%;
  min-height: 740px
}

.text-style .el-form-item__content span,.el-select{margin-left: 25px}
.diaself .el-dialog__header{padding:0 !important}
.el-dialog--center .el-dialog__body {
    padding: 0;
}
.el-form-item{margin-bottom: 10px}
.header-top{
  margin: -20px -20px 20px;
  padding: 15px 20px;
  background: #fff;
  
}
.header-top .title{
  margin:15px 0 0;
  font-weight: 600;
  text-align: center;
  font-size: 20px;
}
.row{
  background: #fff;
  padding: 20px 30px;
  text-align: left
}
.block {
  padding: 20px;
}
.message{
  margin-top: 20px;
}
</style>
  